package com.own.component.common.base.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.own.component.common.login.user.BaseLoginUser;
import com.own.constant.ConstantDateFormatPattern;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * BaseBean
 * 所有实体的基础表
 *
 * @author chenxueli
 * @date 2020/7/6 17:16
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public abstract class BaseBean implements Serializable {

    @Schema(title = "主键id")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    @Schema(title = "创建时间")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonFormat(pattern = ConstantDateFormatPattern.Pattern.DATETIME, timezone = "GMT+8")
    @TableField
    private LocalDateTime gmtCreate;

    /**
     * 设置初始化信息
     */
    public void init() {
        this.gmtCreate = LocalDateTime.now();
    }

    /**
     * 设置初始化信息
     *
     * @param loginUser 登录用户对象
     */
    public void init(BaseLoginUser loginUser) {
        this.gmtCreate = LocalDateTime.now();
    }

    /**
     * 插入之前执行的方法
     */
    public void beforeInsert() {
    }

}
